package com.ruoyi.web.controller.activity;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TActivityRegister;
import com.ruoyi.system.service.ITActivityRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动报名登记Controller
 *
 * @author xiyu
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/activity/register")
public class TActivityRegisterController extends BaseController {
    @Autowired
    private ITActivityRegisterService tActivityRegisterService;

    /**
     * 查询活动报名登记列表
     */
    @PreAuthorize("@ss.hasPermi('activity:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(TActivityRegister tActivityRegister) {
        startPage();
        List<TActivityRegister> list = tActivityRegisterService.selectTActivityRegisterList(tActivityRegister);
        return getDataTable(list);
    }

    /**
     * 导出活动报名登记列表
     */
    @PreAuthorize("@ss.hasPermi('activity:register:export')")
    @Log(title = "活动报名登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TActivityRegister tActivityRegister) {
        List<TActivityRegister> list = tActivityRegisterService.selectTActivityRegisterList(tActivityRegister);
        ExcelUtil<TActivityRegister> util = new ExcelUtil<TActivityRegister>(TActivityRegister.class);
        util.exportExcel(response, list, "活动报名登记数据");
    }

    /**
     * 获取活动报名登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:register:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tActivityRegisterService.selectTActivityRegisterById(id));
    }

    /**
     * 新增活动报名登记
     */
    @PreAuthorize("@ss.hasPermi('activity:register:add')")
    @Log(title = "活动报名登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TActivityRegister tActivityRegister) {
        tActivityRegister.setCreateBy(getUsername());
        return toAjax(tActivityRegisterService.insertTActivityRegister(tActivityRegister));
    }

    /**
     * 修改活动报名登记
     */
    @PreAuthorize("@ss.hasPermi('activity:register:edit')")
    @Log(title = "活动报名登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TActivityRegister tActivityRegister) {
        tActivityRegister.setUpdateBy(getUsername());
        return toAjax(tActivityRegisterService.updateTActivityRegister(tActivityRegister));
    }

    /**
     * 删除活动报名登记
     */
    @PreAuthorize("@ss.hasPermi('activity:register:remove')")
    @Log(title = "活动报名登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids, @PathVariable String rewardStatus) {
        return toAjax(tActivityRegisterService.deleteTActivityRegisterByIds(ids, rewardStatus));
    }
}
